package com.empire.module.sporttery.service.football500rangzhidetail;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import com.empire.module.sporttery.controller.admin.football500rangzhidetail.vo.*;
import com.empire.module.sporttery.dal.dataobject.football500rangzhidetail.Football500RangzhiDetailDO;
import com.empire.framework.common.pojo.PageResult;
import com.empire.framework.common.pojo.PageParam;
import com.empire.framework.common.util.object.BeanUtils;

import com.empire.module.sporttery.dal.mysql.football500rangzhidetail.Football500RangzhiDetailMapper;

import static com.empire.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.empire.module.sporttery.enums.ErrorCodeConstants.*;

/**
 * 让球实时 Service 实现类
 *
 * @author 无敌仙人
 */
@Service
@Validated
public class Football500RangzhiDetailServiceImpl implements Football500RangzhiDetailService {

    @Resource
    private Football500RangzhiDetailMapper football500RangzhiDetailMapper;

    @Override
    public Integer createFootball500RangzhiDetail(Football500RangzhiDetailSaveReqVO createReqVO) {
        // 插入
        Football500RangzhiDetailDO football500RangzhiDetail = BeanUtils.toBean(createReqVO, Football500RangzhiDetailDO.class);
        football500RangzhiDetailMapper.insert(football500RangzhiDetail);
        // 返回
        return football500RangzhiDetail.getId();
    }

    @Override
    public void updateFootball500RangzhiDetail(Football500RangzhiDetailSaveReqVO updateReqVO) {
        // 校验存在
        validateFootball500RangzhiDetailExists(updateReqVO.getId());
        // 更新
        Football500RangzhiDetailDO updateObj = BeanUtils.toBean(updateReqVO, Football500RangzhiDetailDO.class);
        football500RangzhiDetailMapper.updateById(updateObj);
    }

    @Override
    public void deleteFootball500RangzhiDetail(Integer id) {
        // 校验存在
        validateFootball500RangzhiDetailExists(id);
        // 删除
        football500RangzhiDetailMapper.deleteById(id);
    }

    private void validateFootball500RangzhiDetailExists(Integer id) {
        if (football500RangzhiDetailMapper.selectById(id) == null) {
            throw exception(FOOTBALL500_RANGZHI_DETAIL_NOT_EXISTS);
        }
    }

    @Override
    public Football500RangzhiDetailDO getFootball500RangzhiDetail(Integer id) {
        return football500RangzhiDetailMapper.selectById(id);
    }

    @Override
    public PageResult<Football500RangzhiDetailDO> getFootball500RangzhiDetailPage(Football500RangzhiDetailPageReqVO pageReqVO) {
        return football500RangzhiDetailMapper.selectPage(pageReqVO);
    }

}